```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>InnoDB 锁机制深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #2b5876 0%, #4e4376 100%);
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .card {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
        }
        .feature-icon {
            width: 48px;
            height: 48px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 12px;
            margin-bottom: 1rem;
        }
        .highlight {
            position: relative;
            z-index: 1;
        }
        .highlight:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 30%;
            background-color: rgba(74, 144, 226, 0.2);
            z-index: -1;
            transition: all 0.3s ease;
        }
        .highlight:hover:after {
            height: 100%;
        }
        .divider {
            height: 1px;
            background: linear-gradient(to right, transparent, rgba(0,0,0,0.1), transparent);
        }
        .mermaid {
            background: white;
            padding: 1.5rem;
            border-radius: 0.5rem;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero text-white py-20 px-4">
        <div class="max-w-6xl mx-auto">
            <div class="flex flex-col items-center text-center">
                <div class="w-20 h-20 bg-white bg-opacity-20 rounded-full flex items-center justify-center mb-6">
                    <i class="fas fa-lock text-3xl"></i>
                </div>
                <h1 class="text-4xl md:text-5xl font-bold mb-4">InnoDB 锁机制深度解析</h1>
                <p class="text-xl md:text-2xl max-w-3xl opacity-90 mb-8">探索高性能数据库引擎背后的并发控制艺术</p>
                <div class="flex flex-wrap justify-center gap-4">
                    <div class="px-4 py-2 bg-white bg-opacity-10 rounded-full flex items-center">
                        <i class="fas fa-bolt mr-2 text-yellow-300"></i>
                        <span>高并发优化</span>
                    </div>
                    <div class="px-4 py-2 bg-white bg-opacity-10 rounded-full flex items-center">
                        <i class="fas fa-shield-alt mr-2 text-green-300"></i>
                        <span>数据一致性</span>
                    </div>
                    <div class="px-4 py-2 bg-white bg-opacity-10 rounded-full flex items-center">
                        <i class="fas fa-project-diagram mr-2 text-purple-300"></i>
                        <span>复杂锁机制</span>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-4 py-12">
        <!-- Introduction -->
        <section class="mb-16">
            <div class="bg-white rounded-xl p-8 shadow-lg">
                <h2 class="text-2xl font-bold mb-6 text-gray-800">🔍 核心概述</h2>
                <p class="text-lg mb-6 text-gray-700 leading-relaxed">
                    InnoDB 的锁机制是为了处理高并发环境中的事务管理和数据一致性问题而设计的。通过行级锁、间隙锁、意向锁、自适应哈希索引等机制，InnoDB 实现了高效的锁管理和并发控制。
                </p>
                <div class="flex flex-wrap gap-4 mb-6">
                    <div class="px-4 py-2 bg-blue-50 text-blue-700 rounded-full text-sm flex items-center">
                        <i class="fas fa-database mr-2"></i>
                        <span>行级锁</span>
                    </div>
                    <div class="px-4 py-2 bg-purple-50 text-purple-700 rounded-full text-sm flex items-center">
                        <i class="fas fa-code-branch mr-2"></i>
                        <span>间隙锁</span>
                    </div>
                    <div class="px-4 py-2 bg-green-50 text-green-700 rounded-full text-sm flex items-center">
                        <i class="fas fa-flag mr-2"></i>
                        <span>意向锁</span>
                    </div>
                    <div class="px-4 py-2 bg-yellow-50 text-yellow-700 rounded-full text-sm flex items-center">
                        <i class="fas fa-bolt mr-2"></i>
                        <span>自适应哈希索引</span>
                    </div>
                </div>
            </div>
        </section>

        <!-- Lock Types Overview -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 flex items-center">
                <i class="fas fa-key mr-4 text-blue-500"></i>
                <span>锁类型详解</span>
            </h2>
            
            <!-- Record Lock -->
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="card bg-white rounded-xl p-8">
                    <div class="feature-icon bg-blue-100 text-blue-600">
                        <i class="fas fa-bars text-2xl"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4 text-gray-800">行级锁 (Record Lock)</h3>
                    <p class="mb-4 text-gray-700">行级锁是 InnoDB 用于保护数据行在事务中的并发访问。它允许多个事务同时对不同的数据行进行操作，从而提高并发性和性能。</p>
                    
                    <div class="bg-gray-50 p-4 rounded-lg mb-4">
                        <h4 class="font-semibold text-gray-700 mb-2 flex items-center">
                            <i class="fas fa-cog mr-2 text-gray-500"></i>
                            <span>实现方式</span>
                        </h4>
                        <p class="text-gray-600">基于 B+ 树索引实现。当事务需要修改或读取数据时，InnoDB 会锁定相关的索引行。</p>
                    </div>
                    
                    <div class="grid grid-cols-2 gap-4 mb-4">
                        <div class="bg-blue-50 p-3 rounded-lg">
                            <h4 class="font-semibold text-blue-700 mb-1">共享锁 (S Lock)</h4>
                            <p class="text-sm text-blue-600">允许事务读取数据，但不能修改</p>
                        </div>
                        <div class="bg-red-50 p-3 rounded-lg">
                            <h4 class="font-semibold text-red-700 mb-1">排他锁 (X Lock)</h4>
                            <p class="text-sm text-red-600">允许事务读取和修改数据，其他事务不能对该数据行进行任何操作</p>
                        </div>
                    </div>
                    
                    <div class="flex flex-wrap gap-2 mt-2">
                        <div class="px-3 py-1 bg-blue-100 text-blue-700 rounded-full text-xs">提高并发性能</div>
                        <div class="px-3 py-1 bg-yellow-100 text-yellow-700 rounded-full text-xs">可能增加锁争用</div>
                    </div>
                </div>
                
                <div class="card bg-white rounded-xl p-8">
                    <div class="feature-icon bg-purple-100 text-purple-600">
                        <i class="fas fa-map-marker-alt text-2xl"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4 text-gray-800">间隙锁 (Gap Lock)</h3>
                    <p class="mb-4 text-gray-700">间隙锁是一种锁定索引中记录之间的间隙（即不包含实际记录的位置），用于防止在这些间隙中插入新的记录。</p>
                    
                    <div class="bg-gray-50 p-4 rounded-lg mb-4">
                        <h4 class="font-semibold text-gray-700 mb-2 flex items-center">
                            <i class="fas fa-cog mr-2 text-gray-500"></i>
                            <span>实现方式</span>
                        </h4>
                        <p class="text-gray-600">当事务对一行数据加锁时，InnoDB 还会锁定该行之前和之后的间隙。这样可以避免其他事务在这些间隙中插入新记录，从而防止<b class="text-purple-600">幻读</b>问题。</p>
                    </div>
                    
                    <div class="bg-purple-50 p-3 rounded-lg mb-4">
                        <h4 class="font-semibold text-purple-700 mb-2">示例</h4>
                        <p class="text-purple-600">假设有一个索引 `a`，事务 A 选择了 `a = 1`，InnoDB 会锁定 `a < 1` 和 `a > 1` 之间的间隙，防止其他事务在这些间隙中插入新记录。</p>
                    </div>
                    
                    <div class="flex flex-wrap gap-2 mt-2">
                        <div class="px-3 py-1 bg-green-100 text-green-700 rounded-full text-xs">防止幻读</div>
                        <div class="px-3 py-1 bg-yellow-100 text-yellow-700 rounded-full text-xs">可能影响插入性能</div>
                    </div>
                </div>
            </div>
            
            <!-- Intention Lock & Adaptive Hash Index -->
            <div class="grid md:grid-cols-2 gap-8">
                <div class="card bg-white rounded-xl p-8">
                    <div class="feature-icon bg-green-100 text-green-600">
                        <i class="fas fa-flag text-2xl"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4 text-gray-800">意向锁 (Intention Lock)</h3>
                    <p class="mb-4 text-gray-700">意向锁是一种表级锁，用于标记事务打算对某些行加锁。这种锁的主要作用是减少在实际加锁时的冲突和开销。</p>
                    
                    <div class="bg-gray-50 p-4 rounded-lg mb-4">
                        <h4 class="font-semibold text-gray-700 mb-2 flex items-center">
                            <i class="fas fa-cog mr-2 text-gray-500"></i>
                            <span>实现方式</span>
                        </h4>
                        <p class="text-gray-600">意向锁分为意向共享锁（IS）和意向排他锁（IX）。这些锁表示事务打算对某些行加共享锁或排他锁。</p>
                    </div>
                    
                    <div class="grid grid-cols-2 gap-4 mb-4">
                        <div class="bg-blue-50 p-3 rounded-lg">
                            <h4 class="font-semibold text-blue-700 mb-1">意向共享锁 (IS)</h4>
                            <p class="text-sm text-blue-600">标记事务将对某些行加共享锁</p>
                        </div>
                        <div class="bg-red-50 p-3 rounded-lg">
                            <h4 class="font-semibold text-red-700 mb-1">意向排他锁 (IX)</h4>
                            <p class="text-sm text-red-600">标记事务将对某些行加排他锁</p>
                        </div>
                    </div>
                    
                    <div class="flex flex-wrap gap-2 mt-2">
                        <div class="px-3 py-1 bg-green-100 text-green-700 rounded-full text-xs">提高锁效率</div>
                        <div class="px-3 py-1 bg-gray-100 text-gray-700 rounded-full text-xs">额外管理开销</div>
                    </div>
                </div>
                
                <div class="card bg-white rounded-xl p-8">
                    <div class="feature-icon bg-yellow-100 text-yellow-600">
                        <i class="fas fa-bolt text-2xl"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4 text-gray-800">自适应哈希索引 (Adaptive Hash Index)</h3>
                    <p class="mb-4 text-gray-700">自适应哈希索引是一种优化机制，用于加速对热数据的检索。InnoDB 会根据查询的模式动态创建哈希索引，以提高查询性能。</p>
                    
                    <div class="bg-gray-50 p-4 rounded-lg mb-4">
                        <h4 class="font-semibold text-gray-700 mb-2 flex items-center">
                            <i class="fas fa-cog mr-2 text-gray-500"></i>
                            <span>实现方式</span>
                        </h4>
                        <p class="text-gray-600">InnoDB 监视热点查询，并在内存中创建相应的哈希索引。这些哈希索引只存在于内存中，用于快速定位数据。</p>
                    </div>
                    
                    <div class="flex flex-wrap gap-2 mt-2">
                        <div class="px-3 py-1 bg-green-100 text-green-700 rounded-full text-xs">加速热数据访问</div>
                        <div class="px-3 py-1 bg-red-100 text-red-700 rounded-full text-xs">增加内存使用</div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Lock Compatibility & Deadlock -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 flex items-center">
                <i class="fas fa-random mr-4 text-purple-500"></i>
                <span>锁兼容性与死锁处理</span>
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="card bg-white rounded-xl p-8">
                    <h3 class="text-2xl font-bold mb-4 text-gray-800">锁的兼容性和冲突检测</h3>
                    <p class="mb-4 text-gray-700">InnoDB 需要确保不同类型的锁不会导致冲突，且符合事务隔离级别的要求。</p>
                    
                    <div class="mb-6">
                        <h4 class="font-semibold text-lg mb-2 text-gray-700">锁兼容性矩阵</h4>
                        <div class="overflow-x-auto">
                            <table class="min-w-full bg-white rounded-lg overflow-hidden">
                                <thead class="bg-gray-100">
                                    <tr>
                                        <th class="px-4 py-2"></th>
                                        <th class="px-4 py-2">共享锁 (S)</th>
                                        <th class="px-4 py-2">排他锁 (X)</th>
                                        <th class="px-4 py-2">意向共享锁 (IS)</th>
                                        <th class="px-4 py-2">意向排他锁 (IX)</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr class="border-t border-gray-200">
                                        <td class="px-4 py-2 font-medium">共享锁 (S)</td>
                                        <td class="px-4 py-2 text-center bg-green-100 text-green-700">兼容</td>
                                        <td class="px-4 py-2 text-center bg-red-100 text-red-700">冲突</td>
                                        <td class="px-4 py-2 text-center bg-green-100 text-green-700">兼容</td>
                                        <td class="px-4 py-2 text-center bg-red-100 text-red-700">冲突</td>
                                    </tr>
                                    <tr class="border-t border-gray-200">
                                        <td class="px-4 py-2 font-medium">排他锁 (X)</td>
                                        <td class="px-4 py-2 text-center bg-red-100 text-red-700">冲突</td>
                                        <td class="px-4 py-2 text-center bg-red-100 text-red-700">冲突</td>
                                        <td class="px-4 py-2 text-center bg-red-100 text-red-700">冲突</td>
                                        <td class="px-4 py-2 text-center bg-red-100 text-red-700">冲突</td>
                                    </tr>
                                    <tr class="border-t border-gray-200">
                                        <td class="px-4 py-2 font-medium">意向共享锁 (IS)</td>
                                        <td class="px-4 py-2 text-center bg-green-100 text-green-700">兼容</td>
                                        <td class="px-4 py-2 text-center bg-red-100 text-red-700">冲突</td>
                                        <td class="px-4 py-2 text-center bg-green-100 text-green-700">兼容</td>
                                        <td class="px-4 py-2 text-center bg-green-100 text-green-700">兼容</td>
                                    </tr>
                                    <tr class="border-t border-gray-200">
                                        <td class="px-4 py-2 font-medium">意向排他锁 (IX)</td>
                                        <td class="px-4 py-2 text-center bg-red-100 text-red-700">冲突</td>
                                        <td class="px-4 py-2 text-center bg-red-100 text-red-700">冲突</td>
                                        <td class="px-4 py-2 text-center bg-green-100 text-green-700">兼容</td>
                                        <td class="px-4 py-2 text-center bg-green-100 text-green-700">兼容</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                
                <div class="card bg-white rounded-xl p-8">
                    <h3 class="text-2xl font-bold mb-4 text-gray-800">死锁检测</h3>
                    <p class="mb-4 text-gray-700">死锁检测是 InnoDB 用于识别和解决死锁情况的机制。</p>
                    
                    <div class="bg-gray-50 p-4 rounded-lg mb-4">
                        <h4 class="font-semibold text-gray-700 mb-2 flex items-center">
                            <i class="fas fa-cog mr-2 text-gray-500"></i>
                            <span>实现方式</span>
                        </h4>
                        <p class="text-gray-600">InnoDB 使用基于图的死锁检测算法来识别死锁。系统会构建一个等待图，并通过检测图中的循环来识别死锁。当发现死锁时，InnoDB 会选择一个事务作为牺牲者，并回滚其操作以解除死锁。</p>
                    </div>
                    
                    <div class="mermaid">
                        graph LR
                            T1[事务1] -->|请求X锁| R1[资源A]
                            T2[事务2] -->|持有X锁| R1
                            T2 -->|请求X锁| R2[资源B]
                            T1 -->|持有X锁| R2
                    </div>
                </div>
            </div>
        </section>

        <!-- Performance Considerations -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 flex items-center">
                <i class="fas fa-tachometer-alt mr-4 text-blue-500"></i>
                <span>性能考量与最佳实践</span>
            </h2>
            
            <div class="grid md:grid-cols-3 gap-6">
                <div class="card bg-white rounded-xl p-6">
                    <div class="text-blue-500 mb-3">
                        <i class="fas fa-search text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-2 text-gray-800">优化索引设计</h3>
                    <p class="text-gray-600 text-sm">确保查询能够使用索引覆盖，减少不必要的表扫描，从而降低锁争用的可能性。</p>
                </div>
                
                <div class="card bg-white rounded-xl p-6">
                    <div class="text-purple-500 mb-3">
                        <i class="fas fa-clock text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-2 text-gray-800">控制事务时长</h3>
                    <p class="text-gray-600 text-sm">缩短事务执行时间，尽快释放锁资源，减少死锁发生的概率。</p>
                </div>
                
                <div class="card bg-white rounded-xl p-6">
                    <div class="text-green-500 mb-3">
                        <i class="fas fa-layer-group text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-2 text-gray-800">合理选择隔离级别</h3>
                    <p class="text-gray-600 text-sm">根据业务需求选择适当的隔离级别，权衡一致性和并发性能。</p>
                </div>
            </div>
        </section>
    </div>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```